package es.efor.ics.gev.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Version;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The persistent class for the <b>TIPOS_ATRIBUTO</b> database table.
 * 
 */
@Entity()
@Table(name = "TIPOS_ATRIBUTO")
public class TipoAtributo extends BaseObject implements Serializable {

	// static data
	private static final long serialVersionUID = -3224747192126882082L;

	// private instance data
	private Long id;
	private String nombreTipo;		//required
	private String javaClass;		//required
	private Integer version;

	/**
	 * Construct an uninitialized <code>TipoAtributo</code>.
	 */
	protected TipoAtributo() {
	}
	
	/**
	 * Construct an initialized <code>TipoAtributo</code>.
	 * 
	 * @param nombreTipo
	 * @param javaClass
	 */
	public TipoAtributo(String nombreTipo, String javaClass) {
		this.nombreTipo = nombreTipo;
		this.javaClass = javaClass;
	}

	// ********************** Accessor Methods ********************** //

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "TIPO_ATRIBUTO_ID")
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "NOMBRE_TIPO", length = 255, nullable = false)
	public String getNombreTipo() {
		return nombreTipo;
	}

	public void setNombreTipo(String nombreTipo) {
		this.nombreTipo = nombreTipo;
	}

	@Column(name = "JAVA_MAPPING", length = 255, nullable = false)
	public String getJavaClass() {
		return javaClass;
	}

	public void setJavaClass(String javaClass) {
		this.javaClass = javaClass;
	}

	@Version
	@Column(name = "OBJ_VERSION")
	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	// ********************** Common Methods ********************** //

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof TipoAtributo == false) {
			return false;
		}
		if (this == obj) {
			return true;
		}
		TipoAtributo rhs = (TipoAtributo) obj;
		return new EqualsBuilder().append(this.getNombreTipo(),
				rhs.getNombreTipo()).append(this.getJavaClass(),
				rhs.getJavaClass()).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder(17, 37)
		.append(this.getNombreTipo())
		.append(this.getJavaClass())
		.toHashCode();
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).append(
				"nombreTipo", this.getNombreTipo())
				.append("javaClass", this.getJavaClass())
				.toString();
	}

}
